import { atom } from 'jotai';
import { atomWithReset, atomWithStorage } from 'jotai/utils';
import { useImmerAtom, withImmer, atomWithImmer } from 'jotai/immer';

interface DemoStore {
  comData?: Record<string, any>;
  isEditor?: boolean;
}

export const demoAtom = atom<DemoStore>({
  comData: [], // 通信数据
  isEditor: false,
});

// 获取页面组件预览
export const comDataAtom = atom(
  (get) => get(demoAtom).comData,
  (_get, _set, data) => {
    const newData = _get(demoAtom);
    console.log('data', data);

    _set(demoAtom, { ...newData, comData: data as any });
  },
);
